package com.ruoyi.project.demo.order.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.demo.order.domain.CourseOrder;
import com.ruoyi.project.demo.order.service.ICourseOrderService;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 学生预约Controller
 * 
 * @author demo
 * @date 2020-04-19
 */
@Controller
@RequestMapping("/demo/order")
public class CourseOrderController extends BaseController
{
    private String prefix = "demo/order";

    @Autowired
    private ICourseOrderService courseOrderService;

    @RequiresPermissions("demo:order:view")
    @GetMapping()
    public String order()
    {
        return prefix + "/order";
    }

    /**
     * 查询学生预约列表
     */
    @RequiresPermissions("demo:order:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourseOrder courseOrder)
    {
        startPage();
        List<CourseOrder> list = courseOrderService.selectCourseOrderList(courseOrder);
        return getDataTable(list);
    }

    /**
     * 导出学生预约列表
     */
    @RequiresPermissions("demo:order:export")
    @Log(title = "学生预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourseOrder courseOrder)
    {
        List<CourseOrder> list = courseOrderService.selectCourseOrderList(courseOrder);
        ExcelUtil<CourseOrder> util = new ExcelUtil<CourseOrder>(CourseOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 新增学生预约
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生预约
     */
    @RequiresPermissions("demo:order:add")
    @Log(title = "学生预约", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourseOrder courseOrder)
    {
        return toAjax(courseOrderService.insertCourseOrder(courseOrder));
    }

    /**
     * 修改学生预约
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CourseOrder courseOrder = courseOrderService.selectCourseOrderById(id);
        mmap.put("courseOrder", courseOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生预约
     */
    @RequiresPermissions("demo:order:edit")
    @Log(title = "学生预约", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourseOrder courseOrder)
    {
        return toAjax(courseOrderService.updateCourseOrder(courseOrder));
    }

    /**
     * 删除学生预约
     */
    @RequiresPermissions("demo:order:remove")
    @Log(title = "学生预约", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courseOrderService.deleteCourseOrderByIds(ids));
    }
}
